/**
 * Basic markdown formatter for AI chat responses
 * @param {string} text - The text to format
 * @returns {string} Formatted HTML
 */
export const formatMarkdown = (text) => {
  if (!text) return '';
  
  // Basic formatting: bold
  text = text.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>');
  
  // Basic formatting: italic
  text = text.replace(/\*(.*?)\*/g, '<em>$1</em>');
  
  // Code blocks
  text = text.replace(/```([\s\S]*?)```/g, '<pre><code>$1</code></pre>');
  
  // Inline code
  text = text.replace(/`([^`]+)`/g, '<code>$1</code>');
  
  // Headers
  text = text.replace(/^# (.*$)/gm, '<h1>$1</h1>');
  text = text.replace(/^## (.*$)/gm, '<h2>$1</h2>');
  text = text.replace(/^### (.*$)/gm, '<h3>$1</h3>');
  
  // Lists
  text = text.replace(/^\s*\- (.*$)/gm, '<li>$1</li>');
  text = text.replace(/(<li>.*<\/li>)/s, '<ul>$1</ul>');
  
  // Numbered lists
  text = text.replace(/^\s*\d+\. (.*$)/gm, '<li>$1</li>');
  text = text.replace(/(<li>.*<\/li>)/s, '<ol>$1</ol>');
  
  // Links
  text = text.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2">$1</a>');
  
  // Convert line breaks to <br>
  text = text.replace(/\n/g, '<br>');
  
  return text;
}; 